home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 19 / jbcomm12.zip / JBCOMM11.DOC < prev    next >
Text File  |  1988-01-15  |  10KB  |  285 lines

  1.     {JBCOMM:v1.1 by Jim Berg, (c)Copyright 1988 }
  2.  
  3.  
  4. {
  5.  
  6.    The following procedures and functions are to assist the general
  7.    public with communications programming in Turbo Pascal v4.0.  Feel
  8.      free to use these routines in your private programs or programs
  9.      intended for the Public Domain.  If you intend to use these routines
  10.      in a program that you will receive money for, be it Shareware,
  11.      Commercial, or part of your professional program library, you must
  12.      send $15 to:
  13.  
  14.               Jim Berg
  15.                             650 Minnetonka Highland Lane
  16.                             Long Lake, MN 55356
  17.  
  18.    If you find any bugs or have any suggestions, please feel free to
  19.      write, or leave me a message on Terrapin Station, (612)623-0152.
  20.  
  21.              ********* DISCLAIMER *************
  22.  
  23.    If something goes wrong with your hardware while using this library,
  24.      I hereby free myself from any liability with this disclaimer.  As far
  25.      as I know, these routines work.  If something does go wrong, please
  26.      contact me anyway so I may attempt to fix the program.
  27.  
  28. }
  29.  
  30.  
  31.  
  32.  
  33. unit comm;
  34.  
  35. interface
  36.  
  37. uses crt,dos;
  38.  
  39. const
  40.         { constants for Modem Status }
  41.  
  42.          c_DCTS            = 1;   { Delta Clear to Send              }
  43.          c_DDSR            = 2;   { Delta Data Set Ready             }
  44.          c_TERI            = 4;   { Trail End Ring Indicator         }
  45.          c_DRLSD           = 8;   { Delta Receive Line Signal Detect }
  46.          c_CTS             = 16;  { Clear To Send                    }
  47.          c_DSR             = 32;  { Data Set Ready                   }
  48.          c_RI              = 64;  { Ring Indicator                   }
  49.          c_RLSD            = 128; { Receive Line Signal Detect       }
  50.  
  51.         { constants for Line Status  }
  52.  
  53.      c_DR              = 1;   { Data Ready      }
  54.          c_OR              = 2;   { Overrun         }
  55.          c_PE              = 4;   { Parity Error    }
  56.          c_FE              = 8;   { Framing Error   }
  57.          c_BI              = 16;  { Break Interrupt }
  58.          c_THRE            = 32;  { Transmitter Holding Register Empty }
  59.          c_TSRE            = 64;  { Transmitter Shift Register Empty   }
  60.          c_BO              = 128; { Input Buffer Overflow              }
  61.  
  62.         { constants for last interrupt }
  63.  
  64.      c_NONE            = 1;
  65.      c_DATA_READY      = 4;
  66.      c_THR_EMPTY       = 2;
  67.          c_LINE_STATUS     = 6;
  68.          c_MODEM_STATUS    = 0;
  69.  
  70. type porttype          = (com1,com2);
  71. { *** NEW v1.1 *** }
  72.      parityt           = (p_none,p_even,p_odd,p_even_stick,p_odd_stick);
  73.      comstr            = string[255];
  74.          checkstr          = string[20];
  75. { *** NEW v1.1 *** }
  76.          com_info_rec      = record
  77.                                                      offset,
  78.                                                      speed   : word;
  79.                                                      parity  : parityt;
  80.                                                      data,
  81.                                                      stops   : byte;
  82.                                                      active,
  83.                                                      ints_on : boolean
  84.                                                  end;
  85.  
  86.  
  87. { ***************************************************************
  88.   CALLING SOME OF THE ROUTINES BELOW WITHOUT OPENING THE COM PORT
  89.     FIRST MAY CAUSE SOME UNNATURAL THINGS TO OCCUR.
  90.     *************************************************************** }
  91.  
  92.  
  93. { This sets the speed of the serial port to whatever speed you want.
  94.   It doesn't check the speed so any speed is legal, some of which may
  95.     be HARMFUL TO YOUR HARDWARE.  Keep below 19.2kbaud if possible.     }
  96.  
  97. procedure c_set_speed  (cp       : porttype;
  98.                         speed    : word     );
  99.  
  100. { Sets the parity,number of data bits and stop bits.  If number of data
  101.   or stop bits are out of range, data will be 8, or stops will be 1.   }
  102.  
  103. procedure c_set_uart   (cp       : porttype;
  104.                         parity   : parityt;
  105.                                                 data,
  106.                                                 stops    : byte    );
  107.  
  108. { Open the COM port with speed and uart settings.  Create an receive buffer
  109.   of size IBUFFS and a transmit buffer of size OBUFFS. All settings will
  110.     be ignored if the port is already open                                   }
  111.  
  112. procedure c_open       (cp       : porttype;
  113.                         speed    : word;
  114.                                                 parity   : parityt;
  115.                                                 data,
  116.                                                 stops    : byte;
  117.                                                 ibuffs,
  118.                                                 obuffs   : word     );
  119.  
  120. { Close the COM port. If DROPDTR=TRUE, the port will be completely closed,
  121.   if it is FALSE, the interrupts will be turned off, and the port will
  122.     remain active.  That is useful for EXEC or DOORS type programs.         }
  123.  
  124. procedure c_close      (cp       : porttype;
  125.                         dropdtr  : boolean  );
  126.  
  127. { Returns the number of characters waiting in the receive buffer. }
  128.  
  129. function  c_inready    (cp       : porttype ) : word;
  130.  
  131. { Returns the number of characters remaining in the transmit buffer. }
  132.  
  133. function  c_outready   (cp       : porttype ) : word;
  134.  
  135. { Send character through serial port.}
  136.  
  137. procedure c_putc       (cp       : porttype;
  138.                         ch       : char     );
  139.  
  140. { Insert character into receive buffer. }
  141.  
  142. procedure c_insertc    (cp       : porttype;
  143.                         ch       : char     );
  144.  
  145. { Insert String into receive buffer. A '|' translates to a Carriage Return. }
  146.  
  147. procedure c_inserts    (cp       : porttype;
  148.                         outstr   : comstr   );
  149.  
  150. { Wait indefinately for character and return it. }
  151.  
  152. function  c_getc       (cp       : porttype ) : char;
  153.  
  154. { Wait indefinately for character and return it without removing it from the
  155.   receive buffer. }
  156.  
  157. function  c_peekc      (cp       : porttype ) : char;
  158.  
  159. { Reset Received Buffer }
  160.  
  161. procedure c_flush_in   (cp       : porttype );
  162.  
  163. { Reset Transmit Buffer }
  164.  
  165. procedure c_flush_out  (cp       : porttype );
  166.  
  167. { Return True if a carrier is present. }
  168.  
  169. function  c_carrier    (cp       : porttype ) : boolean;
  170.  
  171. { Toggle the DTR.  Dropping the DTR will hangup the modem if it is set up
  172.   right.                                                                 }
  173.  
  174. procedure c_toggle_DTR (cp       : porttype );
  175.  
  176. { Send a break for duration milliseconds }
  177.  
  178. procedure c_send_break (cp       : porttype;
  179.                         duration : word     );
  180.  
  181. { Send a string over serial port.  '|' is a carriage return, and the '~' is
  182.   a 1/4 second delay                                                        }
  183.  
  184. procedure c_puts       (cp       : porttype;
  185.                         outstr   : comstr   );
  186.  
  187. { Wait timeout 1/100s of a second of time to Get a byte from the serial port.
  188.   Will be -1 on timeout or the ascii value. }
  189.  
  190. function  c_getb       (cp       : porttype;
  191.                         timeout  : word     ) : integer;
  192.  
  193. { Will return true if chkstr  is received before the line is quiet for
  194.   timeout hundreds of a second, or false if a timeout occurs.}
  195.  
  196. function  c_waits      (cp       : porttype;
  197.                         chkstr   : checkstr;
  198.                                                 timeout  : word     ) : boolean;
  199.  
  200. { Waits until a string in clst is received or the line is quiet for
  201.   timeout 1/100s of a second. CLST is an array of [1..n] of checkstr.
  202.     It will either return the number of the string that matched, or a
  203.     -1 to indicate a timeout                                            }
  204.  
  205. function  c_waitsn     (cp       : porttype;
  206.                         var clst;
  207.                                                 n        : byte;
  208.                                                 timeout  : word     ) : integer;
  209.  
  210. { This will grab n number of characters out of the receive buffer and put
  211.   them into getbuf.  It   won't wait for n characters though.  It will
  212.     return the number of     characters in could fetch.                    }
  213.  
  214. function  c_get_stream (cp       : porttype;
  215.                         var getbuf;
  216.                                                 n        : word     ) : word;
  217.  
  218. { *** NEW v1.1 *** }
  219.  
  220. { This will grab n number of characters out of the receive buffer and put
  221.   them into getbuf.  It will try to wait for n characters, timeout amount of
  222.     time.  It will return the number of characters in could fetch.      }
  223.  
  224. function  c_tget_stream(cp       : porttype;
  225.                         var getbuf;
  226.                                                 n,
  227.                                                 timeout  : word     ) : word;
  228.  
  229. { This will put n number of characters in putbuf into the transmit buffer.
  230.   If the the transmit buffer is full, it will return.  It returns the number
  231.     of characters put on the buffer. }
  232.  
  233. function  c_put_stream (cp       : porttype;
  234.                         var putbuf;
  235.                                                 n        : word     ) : word;
  236.  
  237. { Returns TRUE if XOFF was received from serial port }
  238.  
  239. function  c_XOFF_received(cp     : porttype ) : boolean;
  240.  
  241. { Returns TRUE if buffer got overflowed and sent an XOFF over the serial
  242.   port. }
  243.  
  244. function  c_XOFF_sent  (cp       : porttype ) : boolean;
  245.  
  246. { Turn on XON/XOFF support. }
  247.  
  248. procedure c_XON_XOFF   (cp       : porttype;
  249.                         on       : boolean  );
  250.  
  251. { Returns last modem status }
  252.  
  253. function  c_statusm    (cp       : porttype ) : byte;
  254.  
  255. { Returns last line status  }
  256.  
  257. function  c_statusl    (cp       : porttype ) : byte;
  258.  
  259. { Return last interrupt information }
  260.  
  261. function  c_lastint    (cp       : porttype ) : byte;
  262.  
  263. { *** NEW v1.1 *** }
  264.  
  265. { This routine will return the current port status for comport cp in the
  266.   record info.    }
  267.  
  268. procedure c_port_info  (cp       : porttype;
  269.                         var info : com_info_rec);
  270.  
  271. { Calculate a CRC }
  272.  
  273. function  CRC_update   (crc      : word;
  274.                         b        : byte     ) : word;
  275.  
  276. { *** NEW v1.1 *** }
  277.  
  278. { Calculates CRC for a block of n bytes }
  279.  
  280. function  block_CRC    (var block;
  281.                         n        : word     ) : word;
  282.  
  283.  
  284. implementation
  285.